<template>
  <div>
    <el-table :data="userlist" border style="width: 100%">
      <el-table-column prop="id" label="编号" width="180">
      </el-table-column>
      <el-table-column prop="username" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="用户角色" width="180">
      </el-table-column>
      <el-table-column label="状态" width="180">
        <template slot-scope="scope">
          <el-tag :type="scope.row.status == 1 ? 'success' : 'warning'">{{
            scope.row.status == 1 ? "启用" : "禁用"
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button size="medium" @click="edit(scope.row)">编辑</el-button>
          <el-button type="danger" size="medium" @click="remake(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pages.page"
      :page-sizes="[1, 2, 3, 4, 5]"
      :page-size="pages.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="userlength"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: ["userlist",'pages','userlength'],
  data() {
    return {
    };
  },
  computed: {},
  created() {},
  mounted() {},
  watch: {},
  methods: {
    handleSizeChange(val) {// 每页多少条数据
      this.pages.size=val
      console.log(this.pages.size);
      this.$emit('getuserList')
      this.pages.page = 1
    },
    handleCurrentChange(val) { // 当前是几页
      this.pages.page=val
      console.log(this.pages.page);
      this.$emit('getuserList')
    },
    remake(val) {// 删除管理员
      
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {  // 删除提示框
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {     
          this.$api.postuserdelete({ id: val.id }).then((res) => { // 
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.$emit('getuserList')
          });
        })
        .catch(() => {   // 取消
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    edit(val) {  // 编辑管理员
      this.$emit('edituser',val)
    }
  },
  components: {},
};
</script>

<style scoped lang="scss">
::v-deep .el-table {
  margin-top: 20px;
}
</style>
